package dbPhase.hypeerweb;


/**
 * AddOrRemoveNode is a class that is set up to allow different roles to perform a different operation
 * to do the appropriate actions to either add or remove a node
 *
 * @pre Domain
 * 	none
 *
 *
 */
public class AddOrRemoveNode {

	/**
	 * Execute starts the process to add a node by invoking the findTerminalNode method.
	 *
	 * @pre start and change have to be non-null and start has to be in the HyPeerWeb that you are
	 * adding change to.
	 *
	 *
	 * @param start - the start node to begin the adding or removing process.
	 * @param change - the node to be changed in some way.
	 */
	public void execute(Node start, Node change) {
		Node terminal = findTerminalNode(start);
		Node point = findPoint(terminal);
		makeChanges(point, change);
	}

	/**
	 * findTerminalNode - finds the last node in the HyPeerWeb so you know where to add the new node
	 *
	 * @pre start is not null and is in the HyPeerWeb you want to add another node to.
	 *
	 * @param start - the node that the findTerminalNode method will begin or continue its search for the
	 * terminal node.
	 * @return Node - that is eventually the terminal node or one that is a step closer.
	 */
	public Node findTerminalNode(Node start) {
		return start.nodeState.find(start);
	}

	/**
	 * findPoint - depending on the role will continue the process to help find the terminal node.
	 *
	 * @pre - terminal is not null and is in the HyPeerWeb that is being changed.
	 * @param terminal - a node that is closer to the terminal node.
	 * @return - terminal node.
	 */
	public Node findPoint(Node terminal) {
		return terminal;
	}

	/**
	 * makeChanges - varies greatly depending on the role that overrides the method.
	 *
	 * @pre point and change are not null.
	 * @param point
	 * @param change
	 */
	public void makeChanges(Node point, Node change) {

	}
}
